#include <cstdio>
#include <algorithm>
#define lc (p<<1)
#define rc (p<<1|1)
using namespace std;
int read(){
	char c=getchar();int x=0;
	while(c<48||c>57) c=getchar();
	do x=x*10+(c^48),c=getchar();
	while(c>=48&&c<=57);
	return x;
}
const int N=1000003;
int n,q;
int s[N];
struct Info{
	int sm,lmx,rmx,mx;
	Info(){}
	Info(int S,int L,int R,int M):sm(S),lmx(L),rmx(R),mx(M){}
	friend Info operator+(const Info a,const Info b){
		return Info(a.sm+b.sm,max(a.lmx,a.sm+b.lmx),max(a.rmx+b.sm,b.rmx),
				max(max(a.mx,b.mx),a.rmx+b.lmx));
	}
}sg[N<<2];
void build(int p=1,int l=1,int r=n){
	if(l==r){
		int vl=max(s[r],0);
		sg[p]=Info(s[r],vl,vl,vl);
		return;
	}
	int mid=(l+r)>>1;
	build(lc,l,mid);
	build(rc,mid+1,r);
	sg[p]=sg[lc]+sg[rc];
}
Info query(int sl,int sr,int p=1,int l=1,int r=n){
	if(sl<=l&&r<=sr) return sg[p];
	int mid=(l+r)>>1;
	if(sr<=mid) return query(sl,sr,lc,l,mid);
	if(sl>mid) return query(sl,sr,rc,mid+1,r);
	return query(sl,sr,lc,l,mid)+query(sl,sr,rc,mid+1,r);
}
int main(){
	freopen("good.in","r",stdin);
	freopen("good.out","w",stdout);
	n=read();q=read();
	char cc=getchar();
	while(cc!=48&&cc!=49) cc=getchar();
	for(int i=1;i<=n;++i){
		if(cc=='1') s[i]=1;
		else s[i]=-1;
		cc=getchar();
	}
	build();
	int res=0;
	while(q--){
		int l=read(),r=read();
		Info tmp=query(l,r);
		if(tmp.sm==-(r-l+1)) res^=(r-l+2);
		else res^=(tmp.mx-tmp.sm);
	}
	printf("%d\n",res);
	return 0;
}
